home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / screen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  2.0 KB  |  111 lines

  1. /*
  2.  * Routines to read and copy the virtual screen image file.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "param.h"
  9. #include "status.h"
  10.  
  11. /*
  12.  * Do a screen dump.  Actually, the screen is already dumped, all we
  13.  * do is copy the file.
  14.  */
  15.  
  16. void
  17. screen_dump()
  18. {
  19.     FILE *fp_in, *fp_out, *my_fopen();
  20.     char buf[MAX_COL];
  21.     void error_win();
  22.     int i;
  23.                     /* open for append */
  24.     if (!(fp_out = my_fopen(param->dumpfile, "a"))) {
  25.         sprintf(buf, "\"%s\" for write", param->dumpfile);
  26.         error_win(0, "Can't open screen dump file", buf);
  27.         return;
  28.     }
  29. #ifdef SHAREDMEM
  30.     for (i=0; i<LINES; i++)
  31.         fprintf(fp_out, "%s\n", status->vs[i]);
  32.  
  33. #else /* SHAREDMEM */
  34.                     /* not guaranteed to exist yet */
  35.     if (!(fp_in = my_fopen(status->vs_path, "r"))) {
  36.         fclose(fp_in);
  37.         return;
  38.     }
  39.                     /* skip the x, y coordinates */
  40.     fgets(buf, 10, fp_in);
  41.  
  42.     while (fgets(buf, MAX_COL, fp_in) != NULL)
  43.         fputs(buf, fp_out);
  44.  
  45.     fclose(fp_in);
  46. #endif /* SHAREDMEM */
  47.  
  48.     fclose(fp_out);
  49.  
  50.     return;
  51. }
  52.  
  53. /*
  54.  * Read the virtual screen and paint its contents to the stdscr using
  55.  * curses(3).  Move the cursor where it belongs.
  56.  */
  57.  
  58. void
  59. load_vs()
  60. {
  61.     register int i;
  62.     FILE *fp, *my_fopen();
  63.     int row, col, max_col;
  64.     char buf[MAX_COL];
  65.  
  66.     clearok(curscr, TRUE);
  67.     erase();
  68.  
  69. #ifdef SHAREDMEM
  70.     for (i=0; i<LINES; i++)
  71.         mvaddstr(i, 0, status->vs[i]);
  72.  
  73.     move(status->row, status->col);
  74. #else /* SHAREDMEM */
  75.                     /* not guaranteed to exist yet */
  76.     if (!(fp = my_fopen(status->vs_path, "r")))
  77.         return;
  78.                     /* get the x, y coordinates */
  79.     fgets(buf, 10, fp);
  80.     sscanf(buf, "%d,%d\n", &row, &col);
  81.  
  82.     i = 0;
  83.     max_col = (COLS > MAX_COL-1) ? MAX_COL-1 : COLS;
  84.     while (fgets(buf, MAX_COL, fp) != NULL) {
  85.                     /* zap the line feed */
  86.         buf[max_col] = '\0';
  87.         mvaddstr(i++, 0, buf);
  88.     }
  89.     fclose(fp);
  90.     move(row, col);
  91. #endif /* SHAREDMEM */
  92.  
  93.     refresh();
  94.     return;
  95. }
  96.  
  97. /*
  98.  * Zap the virtual screen file (or clear it).
  99.  */
  100.  
  101. void
  102. zap_vs()
  103. {
  104. #ifdef SHAREDMEM
  105.     status->clr = 1;
  106. #else /* SHAREDMEM */
  107.     unlink(status->vs_path);
  108. #endif /* SHAREDMEM */
  109.     return;
  110. }
  111.